package test01.demo02.userOperation.service;

import test01.demo02.userOperation.UserIfo.User;
import test01.demo02.userOperation.jdbc.UserJDBC;

import java.sql.ResultSet;
import java.sql.SQLException;

//业务逻辑层，处理具体的业务逻辑
public class UserService {

    UserJDBC ujdbc = new UserJDBC();

    /**
     * 根据用户名查找用户信息
     * @param userName
     * @return
     */
    public User findUserByName(String userName){
        //直接调用jdbc层，从数据库中查找数据
        return ujdbc.selectUser(userName);
    }

    public boolean register(User user){
        int result = ujdbc.addUser(user);
        if (result == 1){
            return true;
        }
        return false;
    }

    /**
     * 实现登录的方法
     */
    public User login(String userName,String pwd){
        return ujdbc.selectUser(userName,pwd);
    }

    /**
     * 实现修改的方法
     */
    public boolean updateMethod(String email,String userName){
        int result = ujdbc.updateEmail(email,userName);
        if (result == 1){
            return true;
        }
        return false;
    }
    /**
     * 实现删除的方法
     */
    public boolean deleteMethod(String userName){
        int result = ujdbc.deleteInfo(userName);
        if (result == 1){
            return true;
        }
        return false;
    }

    public void selectMethod(String userName) throws Exception {
        ujdbc.selectInfo(userName);


    }
}
